package com.xisoft.base.entity;

import com.xisoft.common.db.SqlHelper;
import com.xisoft.common.pubEnv.PubEnvUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;

/**
 * *
 * Created with Description:
 *
 * @version 1.0 <br>
 * @packagename: com.xisoft.devise.entity<br>
 * @author: LiBencheng <br>
 * @computer: licheng <br>
 * @date: Created on 2022/8/11 12:53 <br>
 */
@Data
public class ReferEntity implements Serializable, Cloneable, IBaseVO
{
    public static long serialVersionUID = 1L;

    public ReferEntity( ) { }

    private Map< String,Object > data;
    private String id;
    private String code;
    private String name;
    private String displayName;
    private String fieldName;
    private String pkName;
    private String fields = "";
    private String where;
    private String tableName;

    // {tableName:SYS_ORGANIZATION,fields:ocode AS code,oname AS name,pkName:oid}
    public String getRefSql( )
    {
        return SqlHelper.getSelectSQL(tableName
                , new ArrayList< String >(Arrays.asList(fields.split(PubEnvUtil.COMMA)))
                {{
                    add(pkName);
                    add(fieldName);
                    add(fieldName + "AS name");
                }}.toArray(new String[0])
                , PubEnvUtil.isEmptyObj(where) ? null : where, pkName).split(SqlHelper.where)[0];
    }

    @Override public String getTableName( )
    { return tableName; }

    @Override public String getPrimaryKey( )
    { return pkName; }
}
